import ProxyInterface from '../proxy-interface';
import {FolderPermissionPageModel, MeFolderPermissionModel, PermissionGroupModel, RoleModel} from '@pkpm/pkpm-types';

class RoleProxy implements ProxyInterface<RoleModel> {
    private role: RoleModel = new RoleModel();

    constructor(responseData) {
        let data = responseData.data || responseData;
        Object.assign<RoleModel, any>(this.role, data);
    }

    getModel(): RoleModel {
        return this.role;
    }
}

class RolesProxy implements ProxyInterface<RoleModel[]> {
    private roles: RoleModel[] = [];

    constructor(responseData) {
        let data = responseData.data || responseData;
        data.roles.map((role) => {
            let newRole = new RoleModel();
            this.roles.push(Object.assign<RoleModel, any>(newRole, role));
        });
    }

    getModel(): RoleModel[] {
        return this.roles;
    }
}

class PermissionProxy implements ProxyInterface<PermissionGroupModel> {
    private permission: PermissionGroupModel = new PermissionGroupModel();

    constructor(responseData) {
        let data = responseData.data || responseData;
        Object.assign<PermissionGroupModel, any>(this.permission, data);
    }

    getModel(): PermissionGroupModel {
        return this.permission;
    }
}

class PermissionsProxy implements ProxyInterface<PermissionGroupModel[]> {
    private permissions: PermissionGroupModel[] = [];

    constructor(responseData) {
        let data = responseData.data || responseData;
        data.addinPermissions.map((role) => {
            let newPermission = new PermissionGroupModel();
            this.permissions.push(Object.assign<PermissionGroupModel, any>(newPermission, role));
        });
    }

    getModel(): PermissionGroupModel[] {
        return this.permissions;
    }
}

class FolderPermissionProxy implements ProxyInterface<MeFolderPermissionModel> {
    private folderPermission: MeFolderPermissionModel = new MeFolderPermissionModel();

    constructor(responseData) {
        let data = responseData.data;
        Object.assign<MeFolderPermissionModel, any>(this.folderPermission, data);
    }

    getModel(): MeFolderPermissionModel {
        return this.folderPermission;
    }
}

class FolderPagePermissionProxy implements ProxyInterface<FolderPermissionPageModel> {
    private folderPermission: FolderPermissionPageModel = new FolderPermissionPageModel();

    constructor(responseData) {
        let data = responseData;
        Object.assign<FolderPermissionPageModel, any>(this.folderPermission, data);
    }

    getModel(): FolderPermissionPageModel {
        return this.folderPermission;
    }
}

export {RoleProxy, RolesProxy, PermissionProxy, PermissionsProxy, FolderPermissionProxy, FolderPagePermissionProxy};
